using System;
using System.Collections.Generic;
using System.IO;

using AGG;
using AGG.Transform;
using AGG.Image;
using AGG.VertexSource;
using AGG.UI;
using AGG.Font;

namespace GUITester
{
    public class Fabinator_application : GUIWidget
    {
        TabControlWidget mainNavigationTabControl;
		TextWidget anchorLeft;
		TextWidget anchorRight;
		TextWidget anchorLeftRight;
		
        public Fabinator_application(GuiHalSurface guiSurface)
        {
        }

        public override void OnParentChanged()
        {
            DockToEdge(AnchorFlags.All); // make us match our parents bounds.

            // add our controls after we are attached to our parrent
            anchorLeft = new TextWidget("Left Anchor Text", 12);
            anchorLeft.Location =  new Vector2D(70, 210);
            this.AddChild(anchorLeft);
            anchorLeft.Anchor = AnchorFlags.Left;

			anchorRight = new TextWidget("Right Anchor Text", 12);
            anchorRight.Location =  new Vector2D(70, 250);
            this.AddChild(anchorRight);
            anchorRight.Anchor = AnchorFlags.Right;

			anchorLeftRight = new TextWidget("Left Right Anchor Text", 12);
            anchorLeftRight.Location =  new Vector2D(70, 290);
            this.AddChild(anchorLeftRight);
            anchorLeftRight.Anchor = AnchorFlags.Right | AnchorFlags.Left;

            mainNavigationTabControl = new TabControlWidget();
            this.AddChild(mainNavigationTabControl);
            mainNavigationTabControl.DockToEdge(AnchorFlags.All);

            mainNavigationTabControl.TabPages.Add("page1", new TabPageWidget("Page 1"));
            mainNavigationTabControl.TabPages.Add("page2", new TabPageWidget("Page 2"));

            base.OnParentChanged();
        }
		
        public override void OnDraw(Graphics2D graphics2D)
        {
            this.NewGraphics2D().Clear(new RGBA_Bytes(255, 255, 255));

            //LiberationSansFont.Instance.ShowDebugInfo(graphics2D);

            graphics2D.Rect(anchorLeft.RectToScreen(anchorLeft.Bounds), RGBA_Bytes.Black);
            graphics2D.Rect(anchorRight.RectToScreen(anchorRight.Bounds), RGBA_Bytes.Black);
            graphics2D.Rect(anchorLeftRight.RectToScreen(anchorLeftRight.Bounds), RGBA_Bytes.Black);

            base.OnDraw(graphics2D);
        }

        public static void StartDemo(bool useHWAcceleration)
        {
#if true
            GuiHalFactory.SetGuiBackend("WindowsFormsBitmapBackendGuiFactory");
            GuiHalSurface primaryWindow = GuiHalFactory.CreatePrimarySurface(512, 400, GuiHalSurface.CreateFlags.Resizable, GuiHalSurface.PixelFormat.PixelFormatBgr24);
#else
            GuiHalFactory.SetGuiBackend(new WindowsFormsOpenGLBackendGuiFactory());
            GuiHalSurface primaryWindow = GuiHalFactory.CreatePrimarySurface(512, 400, GuiHalSurface.CreateFlags.Resizable, GuiHalSurface.PixelFormat.PixelFormatBgra32);
#endif

            primaryWindow.Caption = "GUI Tester";

            primaryWindow.AddChild(new Fabinator_application(primaryWindow));
            primaryWindow.Run();
        }

        [STAThread]
        public static void Main(string[] args)
        {
        	StartDemo(false);
        }
    }
}
